package logic

import (
	"context"
	"video-management-system/userrpc/userrpc"

	"video-management-system/api/internal/svc"
	"video-management-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CommentAddLogic) CommentAdd(req *types.CommentAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	if req.Vid == 0 && req.Uid == 0 && req.CommentContent == "" {
		return &types.Response{
			Message: "请输入评论内容",
			Data:    nil,
			Code:    500,
		}, nil
	}
	add, err := l.svcCtx.UserRpc.CommentAdd(l.ctx, &userrpc.CommentAddRequest{
		Vid:            req.Vid,
		Uid:            req.Uid,
		CommentContent: req.CommentContent,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "发布评论成功",
		Data:    add,
		Code:    200,
	}, nil
}
